package cn.iocoder.yudao.module.reading.dal.mysql.community;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.reading.dal.dataobject.community.CommunityCommentLikeDO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 社区评论点赞 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface CommunityCommentLikeMapper extends BaseMapperX<CommunityCommentLikeDO> {

    /**
     * 查询用户对指定评论的点赞记录
     */
    default CommunityCommentLikeDO selectByCommentIdAndUserId(Long commentId, Long userId) {
        return selectOne(CommunityCommentLikeDO::getCommentId, commentId,
                        CommunityCommentLikeDO::getUserId, userId);
    }

    /**
     * 物理删除用户对指定评论的点赞记录
     */
    @Delete("DELETE FROM community_comment_likes WHERE comment_id = #{commentId} AND user_id = #{userId}")
    void deleteByCommentIdAndUserId(@Param("commentId") Long commentId, @Param("userId") Long userId);

    /**
     * 批量查询用户对评论列表的点赞状态
     */
    default List<CommunityCommentLikeDO> selectByCommentIdsAndUserId(List<Long> commentIds, Long userId) {
        return selectList(new LambdaQueryWrapperX<CommunityCommentLikeDO>()
                .in(CommunityCommentLikeDO::getCommentId, commentIds)
                .eq(CommunityCommentLikeDO::getUserId, userId));
    }

}
